# -*- coding:utf-8 -*-
'''本段代码非淘宝，而是本人实际操作的app'''
import os, time, unittest
from appium import webdriver
if __name__ == '__main__':

    PATH = lambda p:os.path.abspath(os.path.join(os.path.dirname(__file__),p))

    #         cap.setCapability("platformName", "Android"); //指定测试平台
    #         cap.setCapability("deviceName", "50045e95"); //指定测试机的ID,通过adb命令`adb devices`获取
    #         cap.setCapability("platformVersion", "10");
    #         cap.setCapability("noReset", true);
    #         cap.setCapability("unicodeKeyboard", true);
    #         // com.ss.android.ugc.aweme.lite/com.ss.android.ugc.aweme.discover.activity.SearchResultActivity
    #         cap.setCapability("appPackage", "com.kuaishou.nebula");
    #         cap.setCapability("appActivity", "com.yxcorp.gifshow.activity.SearchActivity");
    #
    #         driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);

    desired_caps = {}
    desired_caps['platformName'] = 'Android' # 设备系统
    desired_caps['platformVersion'] = '10' # 设备系统版本
    desired_caps['deviceName'] = '50045e95' # 设备名称
    # desired_caps['app'] = PATH(r"E:\tests\GuoYuB2B_2.1.apk")
    desired_caps['appPackage'] = 'com.kuaishou.nebula'
    # com.kuaishou.nebula/com.yxcorp.plugin.search.SearchActivity
    desired_caps['appActivity'] = 'com.yxcorp.gifshow.HomeActivity'
    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
    time.sleep(5)
    # 首页搜索按钮id：com.kuaishou.nebula:id/thanos_home_top_search   X:819,Y:718
    # 删除搜索关键字按钮：com.kuaishou.nebula:id/clear_button
    #：com.kuaishou.nebula:id/clear_button
    driver.find_element_by_id("com.kuaishou.nebula:id/thanos_home_top_search").click()
    try:
        driver.find_element_by_id("com.kuaishou.nebula:id/clear_button").click()
    except:
        print()
    else:
        print()
    driver.find_element_by_id("com.kuaishou.nebula:id/search_layout").click()
    driver.find_element_by_id("com.kuaishou.nebula:id/search_layout").send_keys('飞鹤')
    time.sleep(3)
    try:
        driver.find_element_by_xpath("//*[@text='用户']").click()
    except:
        time.sleep(3)
        driver.find_element_by_id()("com.kuaishou.nebula:id/left_btn").click()
        driver.find_element_by_xpath("//*[@text='用户']").click();
    else:
        print()
    # ThreadUtil.sleep(10, TimeUnit.SECONDS);
    elementsById = driver.find_elements_by_id("com.kuaishou.nebula:id/name");
    # if (elementsById != 'null'  len(elementsById) > 0):
        # elementsById = driver.findElements(By.id("com.kuaishou.nebula:id/name"));
